package com.dhecp.project.hr.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.dhecp.common.annotation.RepeatSubmit;
import com.dhecp.common.core.domain.AjaxResult;
import com.dhecp.common.core.page.TableDataInfo;
import com.dhecp.common.utils.TypeUtils;
import com.dhecp.core.constant.ModuleTable;
import com.dhecp.project.common.controller.BaseModuleController;
import com.dhecp.project.hr.domain.TrainingPlanEntryFormDetail;
import com.dhecp.project.hr.service.TrainingPlanEntryFormDetailService;

/**
 * 培训报名表 控制层
 * @author DH-lwl
 * @version 2020年4月26日
 */
@Controller
@RequestMapping("/hr/trainingplanentryformdetail")
public class TrainingPlanEntryFormDetailController extends BaseModuleController{

	private String prefix = "hr/trainingplanentryformdetail";
    private String moduleTable = ModuleTable.TRAINING_PLAN_ENTRY_FORM_DETAIL;
    
    @Autowired
    private TrainingPlanEntryFormDetailService businessService;
    
    /**
     * 打开查询列表页
     * @param params
     * @return
     * @author DH-Xxj 
     */
	@RequiresPermissions("hr:trainingplanentryformdetail:view")
    @GetMapping()
    public ModelAndView listPage(@RequestParam Map<String, Object> params){
		params.put("moduleTable", moduleTable);
    	params.put("entity", new TrainingPlanEntryFormDetail()); //生成表格gridColumns对应的实体，用于获取实体属性生成表格字段
    	params.put("prefix","hr/hr"); //页面路径
    	
    	ModelAndView mv = this.openListPage(params);
    	mv.addObject("hr", "trainingplanentryformdetail");
		return mv;
    }

	/**
	 * 打开培训报名表详情页
	 * @param params
	 * @return
	 * @author DH-Xxj
	 */
    @GetMapping("/detail")
    public ModelAndView detailPage(@RequestParam Map<String, Object> params){
		params.put("moduleTable", moduleTable);
		ModelAndView mv1 = this.getModelAndView();
		mv1 =  this.gotoModelAndViewErrorPage(params, "guid", "行唯一值"); //验证必要参数
        if (!mv1.isEmpty()){ //缺少必要参数时返回错误提示页面
        	return mv1;
        }
        
		TrainingPlanEntryFormDetail detail = businessService.queryByGuid(params);
		Map<String, Object> detailMap = new HashMap<String, Object> ();
		if (detail != null){
			detailMap = TypeUtils.entityToMap(detail);
		}

    	params.put("detailMap", detailMap); 		//业务数据
    	params.put("prefix", prefix + "/entryformdetail"); 		//页面路径
    	params.put("entity", new TrainingPlanEntryFormDetail());//字段转换参照实体
    	params.put("getFieldAttributesType", "page"); 			//查询全部字段
    	
    	ModelAndView mv = this.openDetailPage(params);
    	
		return mv;
    }
	
	/**
	 * 查询页 列表数据
	 * @param params
	 * @return
	 * @author DH-Xxj
	 */
    @RequiresPermissions("hr:trainingplanentryformdetail:list")
	@GetMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map<String, Object> params){
		params.put("moduleTable", moduleTable);
        List<TrainingPlanEntryFormDetail> list = new ArrayList<TrainingPlanEntryFormDetail>();
        try {
        	list = businessService.queryList(params);
        } catch (Exception e) {
            e.printStackTrace();
            return getDataTable(this.getExceptionMessage(e).toString());            
        }
        return getDataTable(list);
    }

    /**
     * 修改报名状态
     * @param infoItems 必要参数：对应实体类的json格式字符串（需包含：guid,bBmZz,dBmQx，其中bBmZz有效值：已报名、忽略、待报名）
     * @return
     * @author DH-Xxj
     */
    @PostMapping("/changebbmzz")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult updateBBmZz(@RequestParam Map<String, Object> params){		
		params.put("moduleTable", moduleTable);
    	AjaxResult ajaxResult = new AjaxResult();    	
        try {
            ajaxResult= businessService.updateBBmZz(params);
        }catch (Exception e) {
            ajaxResult = AjaxResult.error(this.getExceptionMessage(e));
        }
        return ajaxResult;
    }
    
}
